package com.example.shop_2210.utils

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
@Interceptor(priority = 1)
class LoginInter:IInterceptor {
    override fun init(context: Context?) {

    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //不能不写内容，否则会停留在一个界面没有任何反应
        //登录过或者要跳转到登录界面去时，不拦截
        if("/app/LoginCodeActivity".equals(postcard?.path) ||
            "/app/LoginCodeActivity".equals(postcard?.path)||
            "/app/WebActivity".equals(postcard?.path)||
            SPUtils.getInstance().getString("token").isNotEmpty()){
            callback?.onContinue(postcard)
        }else{
            //未登录过，跳转到非登录界面时，需要跳转到登录界面
            ARouter.getInstance().build("/app/LoginCodeActivity").navigation()
        }
    }
}